#ifndef _Ape_MT_Mutex_h
#define _Ape_MT_Mutex_h

#include <Ape/Object.h>
#include <Ape/String.h>

#if defined(APE_USES_PTHREAD)
#include <pthread.h>
#endif

namespace Ape {
	namespace MT {
		class Mutex : public Object {
			TYPE_NAME ("Ape::MT::Mutex")
		private:
#if defined(APE_USES_PTHREAD)
			pthread_mutex_t m_Handle;
#endif
			
			const String Name;
			bool m_Locked;
		public:
			Mutex (const String mutexName = L"unnamed mutex");
			virtual ~Mutex();
			
			void Lock();
			void Unlock();
			
		};
		
		class MutexLock : public Object {
			TYPE_NAME ("Ape::MT::MutexLock")
		private:
			bool m_Locked;
		public:
			Mutex& M;
			MutexLock (Mutex& m);
			virtual ~MutexLock();
			
			void ForceUnlock();
		};
		
	}
}

#endif // _Ape_MT_Mutex_h
